<template>
  <div class="content">
    <CloudForm :data="forms" v-model="menus" ref='cloud' :method="method" />
  </div>
</template>
<script type="text/javascript">
import forms from './form';
export default {
  data() {
    return {
      forms,
      menus: {},
      method: {
        getUniqueid: this.getUniqueid,
        getRoleList: this.getRoleList
      }
    };
  },
  /**
   * 计算属性
   * @type {Object}
   */
  computed: {

  },
  /**
   * 数据监听
   * @type {Object}
   */
  watch: {

  },
  /**
   * 页面加载执行
   * @return {[type]} [description]
   */
  async mounted() {

  },
  /**
   * 页面方法
   * @type {Object}
   */
  methods: {
    getUniqueid(resolve) {
      this.$cloud.multi().all().then(data => {
        resolve(data);
      }).catch(error => {
        log(error);
      });
    },
    getRoleList(resolve) {
      let role = this.$cloud.userInfo().role
      this.$cloud.roles().all().then(data => {
        let obj = {}
        for (var i in data) {
          obj[data[i].name] = data[i]
        }

        let arr = []
        switch (role) {
          case 'admin':
            arr = data
            break;
          case 'admin_ii':
            arr.push(obj.merchant)
            break;
          default:
            break;
        }


        resolve(arr);
      }).catch(error => {
        log(error);
      });
    },
    affirm(e) {
      let { handleCancel } = e;
      console.log('con', this.$cloud.AppID);
      this.$refs.cloud.submit().then(data => {
        this.$cloud.users().add(data).then(res => {
          console.log('提交返回值', res);
          handleCancel();
        }).catch(error => {
          log(error);
        });
      }).catch(error => {
        log(error);
      });
    }
  }
};

</script>
<style type="text/css" scoped="true">
</style>
